package com.acme.bankapp.domain.bank;

/**
 * Created by anton on 8/18/14.
 */
public class CheckingAccount extends AbstractAccount {
    private double overdraft = 0;

    public CheckingAccount(double balance, double overdraft) {
        super(balance);
        if ( overdraft < 0 ) {
            throw new IllegalArgumentException("Overdraft must be positive.");
        }
        this.overdraft = overdraft;
    }

    @Override
    public double getBalance() {
        return this.balance;
    }

    @Override
    public void deposit(double x) {
        this.balance += x;
    }

    @Override
    public void withdraw(double x) throws OverdraftLimitExceededException {
        if (x > this.balance + this.overdraft) {
            throw new OverdraftLimitExceededException(this.maximumAmountToWithdraw());
        }
        this.balance -= x;
    }

    @Override
    public double maximumAmountToWithdraw() {
        return this.balance + this.overdraft;
    }
}
